﻿namespace Baggr.FeedParser.Atom
{
    using System;
    using System.Xml;
    using System.Xml.Schema;
    using System.Xml.Serialization;

    /// <summary>
    /// Типизированный текст.
    /// </summary>
    public class AtomTypedText
        :IXmlSerializable
    {
        /// <summary>
        /// Элемент поля.
        /// </summary>
        private readonly XmlElement _Element;

        /// <summary>
        /// Вложенный текст.
        /// </summary>
        private string _Text;

        /// <summary>
        /// Стиль текста.
        /// </summary>
        private AtomTextStyles _TextStyle;

        /// <summary>
        /// Конструктор класса.
        /// </summary>
        /// <param name="element">
        /// Элемент поля.
        /// </param>
        public AtomTypedText(XmlElement element)
        {
            _Element = element;
            if (element == null)
                throw new ArgumentNullException("element");
        }

        /// <summary>
        /// Стиль элемента.
        /// </summary>
        public AtomTextStyles Style
        {
            get
            {
                if (_TextStyle == null)
                {
                    _TextStyle = AtomTextStyles.GetFromXmlElement(_Element);
                }

                return _TextStyle;
            }
        }

        /// <summary>
        /// Вложенный текст.
        /// </summary>
        public string Text
        {
            get
            {
                if (_Text == null)
                {
                    _Text = _Element.InnerText;
                }
                return _Text;
            }
        }

        public XmlSchema GetSchema()
        {
            throw new NotImplementedException();
        }

        public void ReadXml(XmlReader reader)
        {
            reader.GetAttribute("type");
        }

        public void WriteXml(XmlWriter writer)
        {
            throw new NotImplementedException();
        }
    }
}
